package org.rockNarwhal.service.impl;

import org.rockNarwhal.domain.Permission;
import org.rockNarwhal.mapper.PermissionMapper;
import org.rockNarwhal.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    PermissionMapper permissionMapper;
    @Override
    public Set<String> listPermissions(String userName) {
        Set<String> permissionSet=null;
        List<Permission> permissions = permissionMapper.listPermissionByUsername(userName);
        if(permissions!=null&&permissions.size()>0){
            permissionSet=new HashSet<>();
            for(Permission p:permissions){
                permissionSet.add(p.getName());
            }
        }
        return permissionSet;
    }
}
